package edu.nf.project.webs.storeOperation;

import edu.nf.project.entitys.entity.storeOperation.convention.operate.Region;
import edu.nf.project.services.exception.derivedAnomalies.CustomerOrderException;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import edu.nf.project.services.storeOperation.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 区域管理控制器
 */
@RestController
@RequestMapping("/api/region")
public class RegionController extends BaseController {
    @Autowired
    private RegionService regionService;

    /**
     * 获取指定门店下属区域信息
     */
    @GetMapping
    public ResultVO<List<Region>> getTargetRegion(Integer[] regionIds) {
        try {
            List<Region> regions = regionService.getTargetRegionList(regionIds);
            return success(regions);
        } catch (Exception e) {
            if (e instanceof CustomerOrderException) {
                throw e;
            }
            System.out.println(e);
            throw new CustomerOrderException(90000, "系统错误，请稍后重试");
        }
    }
}
